'''
http://www.weather.com.cn/data/city3jdata/china.html
http://www.weather.com.cn/data/city3jdata/provshi/10120.html
http://www.weather.com.cn/data/city3jdata/station/1012002.html
'''
import json
import requests

url = r'http://www.weather.com.cn/data/city3jdata/china.html'
url1 = r'http://www.weather.com.cn/data/city3jdata/provshi/%s.html'
url2 = r'http://www.weather.com.cn/data/city3jdata/station/%s.html'
f = open(r'D:/1.txt', 'w')
f1 = open(r'D:/2.txt', 'w')
f2 = open(r'D:/3.txt', 'w')
l = []
req = requests.get(url)
s = req.content.decode('utf-8')
t = json.loads(s)
for i in t:
    l.append(i)
    f.write(t[i]+' ')
for j in l:
    l1 = []
    req1 = requests.get(url1 % j)
    s1 = req1.content.decode('utf-8')
    t1 = json.loads(s1)
    f1.write(s1+'\n')
    for k in t1:
        l1.append(j+k)
    for a in l1:
        if len(l1) > 1:
            req2 = requests.get(url2 % a)
            s2 = req2.content.decode('utf-8')
            t2 = json.loads(s2)
            f2.write(s2+'\n')
            print(s2)
            # for m in t2:
            #     f2.write(t2[m]+' ')
        else:
            pass
f.close()
f1.close()
f2.close()